N4 Mobile uses the value in the Cargo Lot field in various screens to extract the cargo lot ID based on the cargo lot scan format in N4. The extraction of the Lot ID occurs when you press the E button adjacent to the Cargo Lot field in the respective screen. This feature is now available in the following N4 Mobile screens:
Load Vessel (MCRG016)
Discharge Vessel (MCRG004)
Strip Cargo (MCRG024)
Stuff Cargo (MCRG002)
Load Rail (MCRG008)
Unload Rail (MCRG012)
Inspect Cargo (MCRG029)
Truck Load (MCRGLoadOnTruck)
Truck Unload (MCRGUnLoadFromTruck)
Identify Cargo (MCValidateIdentifiedCargo)
Record Damages (MCRecordDamageCargo)
Repair Damages (MCRepairDamageCargo)
Cargo Move (MCSearchMoveCargo)
Print Barcode (MCPrintBarcode)
Before extracting the required barcode, you must define the scan format for the cargo lot ID in the Cargo Lot Id Scan Format view (on page 1) in N4. The BL details are mandatory for the extraction of the cargo lot ID in the Cargo Inventory screens.
For the process to be followed to extract cargo lot ID in the Cargo Inventory screen, see Extracting Cargo Lot ID in the Search form (on page 1).
You can also fetch the BL from N4 based on a groovy code.
To add the sample groovy code in N4:
In the Groovy Plugin form, enter the short description as RdtCustomGroovyImpl.
Enter the groovy code in the Groovy Code field.
Click Save.
If you have added the groovy, N4 considers the BL item number derived from the groovy and allows you to locate the cargo lot ID based on the Cargo Lot Id Scan format view (on page 1).
If you have added the groovy in N4, but have not specified the BL item number in the N4 Mobile screen, N4 considers the first BL item by default to extract the cargo lot ID.
Sample Groovy Code:
* Copy the sample code in the Groovy Code field.
* If RdtCustomGroovyImpl is already available in N4:
* Include the statement updateBlItem(args) in validateChanges method
* And copy all the required method and variable in the existing class
*
*/
import com.navis.apex.business.model.GroovyInjectionBase
import com.navis.cargo.CargoBizMetafield
import com.navis.cargo.CargoConsts
import com.navis.cargo.business.api.CargoManager
import com.navis.cargo.business.model.BillOfLading
import com.navis.cargo.business.model.BlItem
import com.navis.cargo.business.model.CargoLot
import com.navis.cargo.web.CargoMobileGuiMetafield
import com.navis.framework.business.Roastery
import com.navis.framework.portal.FieldChange
import com.navis.framework.portal.FieldChanges
import com.navis.framework.util.BizViolation
import com.navis.inventory.InventoryBizMetafield
import com.navis.inventory.business.api.InventoryCargoUtils
public class RdtCustomGroovyImpl extends GroovyInjectionBase {
final String CLASS_NAME = "RdtCustomGroovyImpl: ";
final String RDT_APPLICATION_NAME = "cargoHandlingProgram";
static final List<String> _formIds = ["MCRG004", "MCRG002", "MCRG016","MCRG024",
"MCRecordDamageCargo","MCRepairDamageCargo",
"MCRGLoadOnTruck","MCRGUnLoadFromTruck",
"MCRG029","MCRG012","MCRG008","MCPrintBarcode",
"MCSearchMoveCargo"];
private CargoManager getCargoManager() {
return (CargoManager) Roastery.getBean(CargoManager.BEAN_ID);
}
public void log(String inMsg) {
super.log(CLASS_NAME + inMsg);
}
public void validateChanges(Map args) throws BizViolation {
updateBlItem(args);
}
private void updateBlItem(Map inArgs) {
if (RDT_APPLICATION_NAME.equalsIgnoreCase((String) inArgs.get(InventoryBizMetafield.RDT_APPLICATION_NAME))) {
Iterator itr = _formIds.iterator();
FieldChanges fcs = null;
while (itr.hasNext()) {
String formId = (String) itr.next();
fcs = (FieldChanges) ((Map) inArgs.get(InventoryBizMetafield.RDT_FORM_CHANGES)).get(formId);
if (fcs != null) {
break;
}
}
if (fcs != null) {
fcs.setFieldChange(CargoBizMetafield.MC_IS_EXTRACT_WITH_GROOVY, Boolean.TRUE);
FieldChange fc = fcs.getFieldChange(CargoMobileGuiMetafield.MC_BL_ITEM_NBR);
Boolean isBlitemNullOrNotPresent = fc ==null? true : fc.getNewValue() == null ? true : false
Boolean isExtractButtonClicked = fcs.hasFieldChange(CargoBizMetafield.MC_IS_EXTRACT_BUTTON_CLICKED) &&
CargoConsts.YES.equals((String) fcs.getFieldChange(CargoBizMetafield.MC_IS_EXTRACT_BUTTON_CLICKED).getNewValue());
if (isExtractButtonClicked
&& fcs.hasFieldChange(CargoMobileGuiMetafield.MC_BL_NBR)
&& fcs.getFieldChange(CargoMobileGuiMetafield.MC_BL_NBR).getNewValue() != null
&& fcs.getFieldChange(CargoMobileGuiMetafield.MC_CARGO_LOT_ID).getNewValue() != null
&& isBlitemNullOrNotPresent
) {
fcs.setFieldChange(CargoBizMetafield.MC_IS_EXTRACT_WITH_GROOVY, Boolean.TRUE)
String lotId = (String) InventoryCargoUtils.getRequiredField(CargoBizMetafield.MC_CARGO_LOT_ID, fcs);
List<BillOfLading> blList = BillOfLading.findAllBillsOfLading(
(String) fcs.getFieldChange(CargoMobileGuiMetafield.MC_BL_NBR).getNewValue());
BillOfLading bl = !blList.isEmpty() ? blList.get(0) : null;
BlItem blItem = bl != null && bl.getBlItems() != null && bl.getBlItems().iterator().hasNext() ?
bl.getBlItems().iterator().next() : null;
if (blItem != null) {
lotId = getCargoManager().findLotIdFromDefinition(lotId, blItem);
for (Iterator iterator = bl.getBlItems().iterator(); iterator.hasNext();) {
BlItem blItemItr = (BlItem) iterator.next();
CargoLot cargoLot = CargoLot.findCargoLot(blItemItr, lotId);
if (cargoLot != null) {
fcs.setFieldChange(CargoMobileGuiMetafield.MC_BL_ITEM_NBR, cargoLot.getLotBlitemInbound().getBlitemNbr());
break;
}
}
}
}
}
}
}
}